using UnityEngine;

public class PlayerBlackholeState : PlayerState
{
    private float flyTime = 0.4f;
    private bool skillUsed;
    private float defaultGravity;

    public PlayerBlackholeState(Player player, string animBoolName) : base(player, animBoolName) { }

    public override void AnimationFinishedTrigger()
    {
        base.AnimationFinishedTrigger();
    }

    public override void Enter()
    {
        base.Enter();
        defaultGravity = rb.gravityScale;
        skillUsed = false;
        stateTimer = flyTime;
        rb.gravityScale = 0f;
    }

    public override void Exit()
    {
        base.Exit();
        rb.gravityScale = defaultGravity;
        player.Fx.MakeTransprent(false);
    }

    public override void Update()
    {
        base.Update();
        if (stateTimer > 0)
        {
            rb.velocity = new Vector2(0, 15);
        }
        else if (stateTimer < 0)
        {
            rb.velocity = new Vector2(0, -0.1f);
            if (!skillUsed)
            {
                if (player.SkillManager.Blackhole.CanUseSkill())
                {
                    skillUsed = true;
                }
            }
        }
        if (player.SkillManager.Blackhole.Completed())
        {
            StateMachine.ChangeState(player.AirState);
        }
    }
}
